//
//  Sprite.h
//  Prism
//
//  Created by Bas du Pre on 20-05-11.
//  Copyright 2011 UU. All rights reserved.
//

#pragma once

#include "Node.h"
#include "Texture.h"
#include "TextureFrame.h"
#include "Animation.h"

namespace Prism {
namespace Graphics {
    
    class Sprite : public Node {
    public:
        Sprite();
        Sprite(Texture *texture);
        Sprite(File &file);
        Sprite(String filename);
        Sprite(TextureFrame *textureFrame);
        Sprite(TextureFrame &textureFrame);
        Sprite(Animation *animation);
        virtual ~Sprite();
        
        void init();
        
        Texture *texture();
        void setTexture(Texture* texture);
        TextureFrame* textureFrame();
        void setTextureFrame(TextureFrame &textureFrame);
        Rect rect();
        void setRect(Rect rect);   
        
        void setAnimation(Animation *animation);
        Animation *animation();
        void removeAnimation();
        
        virtual Rect boundingBox();
        
        virtual String toString();
        
        /*enum Mode {
            ModeTexture,
            ModeTextureFrame,
            ModeAnimation
        } mode;*/
        
        #if PRISM_OS_IOS && PRISM_BUILDENGINE
        #include "iOS/ios_Sprite.h"
        #elif PRISM_TARGET_SDL
        #include "sdl/sdl_Sprite.h"
        #endif
        
    private:
        TextureFrame *_textureFrame;
        Animation *_animation;
        PInt _animationFrame;
        
        void onTextureFrameChanged(void* sender, EventArgs* e);
        void onUpdateAnimate(void* sender, UpdateEventArgs* e);
        PFloat _dt;
        
        bool myTexture;        
        
        void native_loadSprite();
        void native_updateSprite();
        Rect native_boundingBox();
        
    };
}
}
